Skip to content

feat: Support for schema containing format #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 9, 2021
Merged

Conversation

Himenon
Copy link
Owner

@Himenon Himenon commented Nov 9, 2021

Summary

  • Add option to convert Schema with format to any type definition.

related issues

Design

Input Schema

components:
  schemas:
    Binary:
      type: string
      format: binary
    IntOrString:
      type: string
      format: int-or-string
    AandB:
      type: string
      format: A-and-B

Generator Option

import { CodeGenerator, Option } from "@himenon/openapi-typescript-code-generator";
const option: Option = {
  convertOption: {
    formatConversions: [
      {
        selector: {
          format: "binary",
        },
        output: {
          type: ["Blob"],
        },
      },
      {
        selector: {
          format: "int-or-string",
        },
        output: {
          type: ["number", "string"],
        },
      },
      {
        selector: {
          format: "A-and-B",
        },
        output: {
          type: ["A", "B"],
          multiType: "allOf",
        },
      },
    ],
  },
};
const codeGenerator = new CodeGenerator(inputFilename, option);

Output

export namespace Schemas {
    export type Binary = Blob;
    export type IntOrString = number | string;
    export type AandB = A & B;
}

@Himenon Himenon merged commit 24c7bd2 into main Nov 9, 2021
@Himenon Himenon deleted the feat/convert-option branch November 9, 2021 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: PDFをダウンロードするAPIの型
1 participant